home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9077 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: news.scruz.net!usenet
  2. From: Dave Navarro <dave@powerbasic.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Determining the serial number on a hard disk
  5. Date: Thu, 07 Mar 1996 15:34:15 -0800
  6. Organization: PowerBASIC, Inc. (http://www.powerbasic.com)
  7. Message-ID: <313F7277.506C@powerbasic.com>
  8. References: <207_9602292012@dudd.uniserve.com>
  9. NNTP-Posting-Host: 165.227.103.90
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. >  jo> I'm using MSVC.  Does anyone know how to determine the serial number
  16. >  jo> of a disk.  This is the number you get when you issue a VOL command
  17. >  jo> from the DOS prompt.  I was thinking of using this number as a method
  18. >  jo> of copy protection.
  19. >  jo> Anybody know the sector, head, and cylinder where this number is
  20. >  jo> stored?
  21. > I wouldn't know that... but if you get ahold of an interrupt list, you
  22. > might do best to use the bios to tell you that.  Just use int86 or
  23. > whatever.
  24.  
  25. Here's some Basic code that can be easily translated:
  26.  
  27. '
  28. ' DISKID.BAS    reports disk volume and serial number from boot sector
  29. '
  30. ' Author:     Christy Gemmell (christy.gemmell@almac.co.uk)
  31. ' Date:       12/4/1992
  32. '
  33. ' Captured from alt.lang.basic newsgroup on July 20, 1995 and converted
  34. ' to PowerBASIC by Dave Navarro, Jr. (dave@powerbasic.com)
  35. '
  36.  
  37. %AX = 1  :  %BX = 1
  38. %CX = 1  :  %DX = 1
  39. %DS = 8
  40.  
  41. TYPE ParaBlock
  42.   Info  AS INTEGER                ' Call information level
  43.   SerNo AS LONG                   ' Disk serial number
  44.   Label AS STRING * 11            ' Volume label
  45.   FlSys AS STRING * 8             ' File system type
  46. END TYPE
  47.  
  48. INPUT "Which drive - <Enter> for default"; D$
  49.  
  50. GetDiskID D$, S$, V$, F$
  51. PRINT
  52. PRINT "Disk information for drive "; D$
  53. PRINT "----------------------------"
  54. PRINT "Volume label  : "; V$
  55. PRINT "Serial number : "; S$
  56. PRINT "File system   : "; F$
  57. END
  58.  
  59. SUB GetDiskID (Drive$, Serial$, Volume$, FileSys$)
  60.  
  61.   DIM Para AS ParaBlock               ' Buffer for drive parameter block
  62.  
  63.   Para.Info = 0                       ' Information level always zero
  64.  
  65.   REG %AX, &H440D                     ' Generic IOCTL device request
  66.   IF Drive$ = "" THEN                 ' If no drive specified
  67.     REG %BX, 0                        '    then use default
  68.   ELSE                                ' Otherwise convert
  69.     REG %BX, ASC(UCASE$(Drive$)) - 64 ' drive letter to number
  70.   END IF                              '     A: = 1, B: = 2 etc
  71.   REG %CX, &H0866                     ' Subfunction: get drive ID
  72.   REG %DX, VARPTR(para)               ' Offset of buffer in DX
  73.   REG %DS, VARSEG(Para)               ' Segment of buffer in DS
  74.   CALL INTERRUPT &H21                 ' Invoke DOS
  75.  
  76.   Serial$ = HEX$(Para.SerNo)          ' Get serial number
  77.   Volume$ = Para.Label                ' Get volume label
  78.   FileSy$ = Para.FlSys                ' Get file system type
  79.  
  80. END SUB
  81.  
  82. --Dave
  83.